package com.fuda.trade.model

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json

@Serializable
data class TradeStrategy(
    @SerialName("id")
    val id: FudaThing?,
    val klt: String?=null,
    val seqno: Int?=null,
    val name: String?=null,
    val desc: String?=null,
    @SerialName("script_verified")val scriptVerified: Boolean?=null,
    val script: String?=null,
    @SerialName("kl_window")val klWindow: Int?=null,
    @SerialName("is_online")val isOnline: Boolean?=null,
    @SerialName("is_gen_auto_trade_command")val isGenAutoTradeCommand: Boolean?=null,

    val data: TradeStrategyData?,
    @SerialName("last_updated")val lastUpdated: String?=null
){
    // Secondary constructor for creating a TradeOrder with only id and data
    constructor(id: FudaThing, data: TradeStrategyData) :this(
        id = id,
        klt = null,
        seqno = null,
        name=null,
        data = data,
    )

    companion object {
        private val json = Json {
            encodeDefaults = true
            ignoreUnknownKeys=true
        }

        fun serialize(command: TradeStrategy): String {
            return json.encodeToString(command)
        }

        fun deserialize(jsonStr: String): TradeStrategy {
            return json.decodeFromString(jsonStr)
        }

        fun deserializeList(jsonStr: String): List<TradeStrategy> {
            return json.decodeFromString(jsonStr)
        }
    }
}

